from django.contrib import admin
from booktest.models import BooktestAreainfo


# Register your models here.


class AreaStackedInline(admin.StackedInline):
    # 写多类的名字
    model = BooktestAreainfo
    extra = 1


class AreaTabularInline(admin.TabularInline):
    # 写多类的名字
    model = BooktestAreainfo
    extra = 1


class AreaInfoAdmin(admin.ModelAdmin):
    """地区模型管理类"""
    # 列表页的属性
    list_per_page = 10  # 每页显示10条数据
    list_display = ['id', 'atitle', 'title', 'parent']  # 可以写模型类的属性 或者 方法名
    actions_on_bottom = True
    actions_on_top = False
    list_filter = ['atitle']  # 列表页右侧过滤栏
    search_fields = ['atitle']  # 列表页上方的搜索框

    # 编辑页的属性
    # fields = ['aparent', 'atitle']
    # fields和fieldsets只能二者选其一
    fieldsets = (
        ('基本', {'fields': ['atitle']}),
        ('高级', {'fields': ['aparent']})
    )

    # 以块的方式嵌入指定类的下级地区数据
    # inlines = [AreaStackedInline]
    inlines = [AreaTabularInline]


# 访问http://192.168.1.102:8000/admin/ 的时候，能够看到模型类的数据
admin.site.register(BooktestAreainfo, AreaInfoAdmin)
